package com.woniuxy.wallet.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.entity.Escort;
import com.woniuxy.commons.entity.Order;
import com.woniuxy.commons.entity.ServiceItem;
import com.woniuxy.commons.entity.Wallet;
import com.woniuxy.commons.util.ResponseResult;
import com.woniuxy.wallet.entity.A;
import com.woniuxy.wallet.mapper.WalletMapper;
import com.woniuxy.wallet.service.WalletService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class WalletServiceImpl implements WalletService {

    @Resource
    private WalletMapper walletMapper;

    @Override
    public ResponseResult firstPage(int pageNum,int handleSize) {
        PageHelper.startPage(pageNum,handleSize);

        List<Wallet> wallets = walletMapper.all();

        PageInfo<Wallet> pageInfo = PageInfo.of(wallets);

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(pageInfo);

        return responseResult;
    }

    @Override
    public ResponseResult balance() {

        double balance = walletMapper.balance();

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(balance);

        return responseResult;
    }

    @Override
    public ResponseResult waitMoney() {

        double waitMoney = walletMapper.waitMoney();

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(waitMoney);

        return responseResult;
    }

    @Override
    public ResponseResult finish() {

        double finish = walletMapper.finish();

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(finish);

        return responseResult;
    }

    @Override
    public ResponseResult amount() {

        double amount = walletMapper.amount();

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(amount);

        return responseResult;
    }

    @Override
    public ResponseResult findAll1() {

        List<Wallet> all1 = walletMapper.findAll1();

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(all1);

        return responseResult;
    }

    @Override
    public ResponseResult findAll2() {

        List<Wallet> all2 = walletMapper.findAll2();

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(all2);

        return responseResult;
    }

    @Override
    public ResponseResult findTime1(String ot) {

        List<Wallet> time1 = walletMapper.findTime1(ot);

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(time1);

        return responseResult;
    }

    @Override
    public ResponseResult findTime2(String ot) {
        List<Wallet> time2 = walletMapper.findTime2(ot);

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(time2);

        return responseResult;
    }

    @Override
    public ResponseResult shaixuan(Wallet wallet) {



        List<Wallet> filtrate = walletMapper.shaixuan(wallet);

        PageInfo<Wallet> pageInfo = PageInfo.of(filtrate);

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(pageInfo);

        return responseResult;
    }

    @Override
    public ResponseResult allCS(int pageNum,int handleSize) {

        PageHelper.startPage(pageNum,handleSize);

        List<Order> orders = walletMapper.allCS();

        PageInfo<Order> pageInfo = PageInfo.of(orders);

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(pageInfo);

        return responseResult;
    }

    @Override
    public ResponseResult findT(A aaa) {

        List<Order> t = walletMapper.findT(aaa);

        ResponseResult responseResult = new ResponseResult();

        responseResult.setData(t);

        return responseResult;
    }

    @Override
    public Escort findEByName(String name) {

        Escort eByName = walletMapper.findEByName(name);

        return eByName;
    }

    @Override
    public void updateStatus(String no) {

        walletMapper.updateStatus(no);

    }

    @Override
    public void insertWallet(Order order,int i) {

//        Wallet wallet = new Wallet();
//
//        wallet.setOrderId(order.getNo());
//
//        wallet.setDetailTime(order.getOrderTime());
//
//        if(i == 1){
//
//            wallet.setType("收入");
//
//            BigDecimal price = order.getServiceItem().getPrice();
//
//            double v = price.doubleValue();
//
//            wallet.setIncome(v);
//
//            ResponseResult responseResult = balance();
//
//            Double data = (Double) responseResult.getData();
//
//            data = data + v;
//
//            wallet.setBalance(data);
//
//            wallet.setStatus(1);
//
//        }else {
//
//            wallet.setType("支出");
//
//            BigDecimal price = order.getServiceItem().getPrice();
//
//            double v = price.doubleValue();
//
//            v =v*0.1;
//
//            wallet.setAmount(v);
//
//            ResponseResult responseResult = balance();
//
//            Double data = (Double) responseResult.getData();
//
//            data = data - v;
//
//            wallet.setBalance(data);
//
//            wallet.setStatus(2);
//
//        }
//
//        String name = order.getEscort().getPayee();
//
//        wallet.setTechnician(name);
//
//        wallet.setPayType("支付宝");
//
//        Date date = new Date();
//
//        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");
//
//        String s = dateFormat.format(date);
//
//        wallet.setOrderTime(s);
//
//        walletMapper.insertWallet(wallet);


    }

    @Override
    public ServiceItem findById(long id) {

        ServiceItem serviceItem = walletMapper.findById(id);

        return serviceItem;
    }

    @Override
    public Escort findEscortById(int id) {

        Escort escort = walletMapper.findEscortById(id);

        return escort;
    }


}
